package com.study.lambda.basedemo;

import java.util.Arrays;
import java.util.Random;
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.IntUnaryOperator;

/**
 * @author 朝花不迟暮
 * @version 1.0
 * @date 2021/5/29 21:36
 */
public class LambdaDemo05
{
    public static void main1(String[] args)
    {
        // Function<Integer, String> func = a -> String.valueOf(a);
        Function<Integer, String> func = String::valueOf;
        String s = func.apply(99);
        System.out.println("s = " + s);
    }

    public static void main2(String[] args)
    {
        Consumer<String> consumer = System.out::println;
        consumer.accept("javaboy");
    }

    public static void main3(String[] args)
    {
        // BiFunction<Integer, Integer, Double> func = (a, b) -> Math.pow(a, b);
        BiFunction<Integer, Integer, Double> func = Math::pow;
        Double result = func.apply(3, 4);
        System.out.println("result = " + result);
    }

    public static void main4(String[] args)
    {
        Random random = new Random();
        // IntUnaryOperator func = i -> random.nextInt(i);
        IntUnaryOperator func = random::nextInt;
        Integer r = func.applyAsInt(10);
        System.out.println("r = " + r);
    }

    public static void main(String[] args)
    {
        String[] stringArray = {"Barbara", "Mary", "James"};
        Arrays.sort(stringArray, String.CASE_INSENSITIVE_ORDER);
        System.out.println(Arrays.toString(stringArray));
    }
}
